home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / beachball.cpt / beachball ƒ / beach.c next >
Text File  |  1988-01-06  |  3KB  |  132 lines

  1. /*
  2. (c) copyright 1987 Symantec Corporation.  For use with THINK's Lightspeed C only.
  3.  
  4. You may incorporate these routines in any of your programs, for commercial distribution
  5. or otherwise, but you may not charge for the specific use of this code.  Symantec 
  6. Corporation makes no warranty regarding the fitness of this software for any particular
  7. purpose.
  8.  
  9. beach.c -- Simple little program that rolls a "beach ball cursor" while something
  10. important but time-consuming is happening.  Lots of commercial applications are 
  11. doing this as a standard way to keep the user comfortable that the machine hasn't
  12. crashed -- that it's still busy doing whatever its supposed to be doing.
  13.  
  14. Also included is the resource source in beach.r.  There are four cursors with id's
  15. of 256, 257, 258 and 259, representing each of the four possible beach ball states.
  16.  
  17. To change the rate of rotation, just change the constant "beachrate".
  18.  
  19. To use the beachball in your application, just call "setupbeachballs" at the beginning
  20. of your program and add calls to "rollbeachball" in places where your program is 
  21. doing a lot of computation, or reading from disk, or printing, or compiling or
  22. whatever...
  23.  
  24. First upload to LVTFORUM -- 1/6/88, by Dave Winer/LVT.
  25. */
  26.  
  27. #include "QuickDraw.h"
  28. #include "ToolboxUtil.h"
  29.  
  30. #include "standard.h"
  31.  
  32.  
  33. /*
  34. set beachrate to     10 for a ball that rolls     6 times per second
  35.                     15                            4
  36.                     20                            3
  37.                     30                            2
  38.                     60                            1
  39.                     
  40. get the idea?
  41. */
  42.     #define beachrate 5 /*decrease ==> ball rolls faster, increase ==> slower*/
  43.  
  44.  
  45. int beachstate = 1; /*current state of the beachball, varies from 0 to 3*/
  46.  
  47. long tickalarm; /*the time the ball is scheduled to roll again*/
  48.  
  49. CursHandle beachballs [4];
  50.  
  51.  
  52. boolean setupbeachballs () {
  53.  
  54.     /*
  55.     call this routine before your first call to rollbeachball
  56.     */
  57.     
  58.     register int i;
  59.     register CursHandle cursor;
  60.     
  61.     tickalarm = TickCount (); /*roll the ball the first time rollbeachball is called*/
  62.     
  63.     for (i = 0; i <= 3; i++) {
  64.     
  65.         cursor = GetCursor (256 + i); /*pull it out of the resource file*/
  66.         
  67.         if (cursor == nil) /*error loading the cursor*/
  68.             return (false);
  69.             
  70.         beachballs [i] = cursor; /*no error, copy into array*/
  71.         } /*for*/
  72.     
  73.     return (true); /*all beachballs loaded correctly*/
  74.     } /*setupbeachballs*/
  75.     
  76.     
  77. rollbeachball () {
  78.     
  79.     /*
  80.     if enough time has elapsed since the last roll, reset the timer and
  81.     roll the beachball into the next state.
  82.     */
  83.     
  84.     register long tc; 
  85.     register CursHandle cursor;
  86.     
  87.     tc = TickCount ();
  88.     
  89.     if (tc < tickalarm) /*not enough time has elapsed since last roll*/
  90.         return;
  91.         
  92.     tickalarm = tc + beachrate; /*time for the next roll*/
  93.     
  94.     beachstate = (beachstate + 1) mod 4; /*advance to next state*/
  95.     
  96.     cursor = beachballs [beachstate]; /*copy from array*/
  97.     
  98.     SetCursor (*cursor); /*show the next state*/
  99.     } /*rollbeachball*/
  100.     
  101.     
  102. main () {
  103.     
  104.     InitGraf (&thePort); /*the usual stuff*/
  105.     
  106.     InitFonts ();
  107.     
  108.     InitWindows ();
  109.     
  110.     InitMenus ();
  111.     
  112.     TEInit ();
  113.     
  114.     InitDialogs (nil);
  115.     
  116.     InitCursor ();
  117.     
  118.     MaxApplZone ();
  119.  
  120.     if (!setupbeachballs ()) {
  121.     
  122.         SysBeep (1); /*listen for this, check the resource file, must be beach.rsrc*/
  123.         
  124.         return;
  125.         }
  126.         
  127.     while (!Button ()) /*loop until you press mouse button*/
  128.         
  129.         rollbeachball (); /*advance to next state if enough time has elapsed*/
  130.     } /*main*/
  131.     
  132.